﻿using INTEX.DataBase.Tools;
using ITXHWEB.Models;
using System.Collections.Generic;
using System.Data;
using System.Management;
using System.Net;
using System.Net.Security;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using WPFExcelReport;
using WPFExcelReport.Helpers;
namespace ITXHWEB.Controllers
{

    //[Authorize]
    //[InitializeSimpleMembership]
    public partial class ITXController : Controller
    {
        public string date = "", time = "", stime = "";
        public DataRow dwData;
        public DataSet SResult;
        public string filter = "";
        public DataRow[] rows = null;
        ///不登陆不创建用户环境。
        ///登陆后，用IP地址创建一个环境
        /// <summary>
        /// 设置运行环境
        /// </summary>
        /// 
        public Dictionary<string, object> PM;
        public string MAPP
        {
            get
            {
                if (!ENVMAIN.ContainsKey("MAPP"))
                {
                    ENVMAIN.Add("MAPP", "");
                }
                return (string)ENVMAIN["MAPP"];
            }

            set
            {
                ENVMAIN["MAPP"] = value;
            }
        }
        public string ClientIP
        {
            get
            {
                return GetIp();
            }
        }
        public Dictionary<string, object> ENVMAIN
        {
            get
            {
                return app.ENVMAIN(ClientIP);
            }
        }
        public ITXModel LMODEL
        {
            get
            {
                if (!ENVMAIN.ContainsKey("LMODEL"))
                {
                    ENVMAIN.Add("LMODEL", null);
                }
                return (ITXModel)ENVMAIN["LMODEL"];
            }
            set
            {
                ENVMAIN["LMODEL"] = value;
            }
        }
        public string INFO
        {
            get
            {
                if (!ENVMAIN.ContainsKey("INFO"))
                {
                    ENVMAIN.Add("INFO", "");
                }
                return (string)ENVMAIN["INFO"];
            }
            set
            {
                ENVMAIN["INFO"] = value;
            }
        }
        #region====PDC=================
        /*
        private UaSession _UAClient;
        public UaSession UAClient
        {
            get
            {
                if (!ENVMAIN.ContainsKey("UAClient"))
                {
                    var config = new ApplicationConfiguration()
                    {
                        ApplicationName = "ConverterSystems.TestClient",
                        ApplicationType = ApplicationType.Client,
                        SecurityConfiguration = new SecurityConfiguration { ApplicationCertificate = new CertificateIdentifier { StoreType = @"Windows", StorePath = @"CurrentUser\My", SubjectName = Utils.Format(@"CN={0}, DC={1}", "ConverterSystems.TestClient", System.Net.Dns.GetHostName()) }, TrustedPeerCertificates = new CertificateTrustList { StoreType = @"Windows", StorePath = @"CurrentUser\TrustedPeople", }, NonceLength = 32, AutoAcceptUntrustedCertificates = true },
                        TransportConfigurations = new TransportConfigurationCollection(),
                        TransportQuotas = new TransportQuotas { OperationTimeout = 15000 },
                        ClientConfiguration = new ClientConfiguration { DefaultSessionTimeout = 60000 }
                    };
                    config.Validate(ApplicationType.Client);
                    config.EnsureApplicationCertificate();
                    if (config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
                    {
                        config.CertificateValidator.CertificateValidation += (s, e) => { e.Accept = (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted); };
                        ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => { return (d == SslPolicyErrors.None) || (d == SslPolicyErrors.RemoteCertificateChainErrors); };
                    }
                    _UAClient = new UaSession(config, "opc.tcp://192.168.31.119:51212");
                    ENVMAIN.Add("UAClient", _UAClient);                   
                }
                return (UaSession)ENVMAIN["UAClient"]; 
            }
            set
            {
                ENVMAIN["UAClient"] = value;
            }
        }
        */
        ABFOLGEModel _MABF;
        public ABFOLGEModel MABF
        {
            get
            {
                if (!ENVMAIN.ContainsKey("MABF"))
                {
                    _MABF = new ABFOLGEModel();
                    /*if (UAClient != null)
                    {
                        var subscription = new Subscription(UAClient.DefaultSubscription) { PublishingInterval = 250 };
                        // Step 5 - Configure the subsscription with all the [MonitoredItem] attributes found in the model
                        subscription.WithModel(_MABF).AddBindings()
                                 .AddBinding(m => m.Robot1Axis4, new MonitoredItem { StartNodeId = "ns=2;s=Robot1_Axis4" }); ;
                        // Step 6 - Add the subscription to the session.
                        UAClient.AddSubscription(subscription);
                    }*/
                    ENVMAIN.Add("MABF", _MABF);
                    WRUNID = _MABF.WRUNID;
                }
                return (ABFOLGEModel)ENVMAIN["MABF"];
            }
            set
            {
                ENVMAIN["MABF"] = value;
            }
        }

        public AMClient TAMClient
        {
            get
            {
                if (!ENVMAIN.ContainsKey("TAMClient"))
                {
                    ENVMAIN["TAMClient"] = new AMClient(true);
                }
                return (AMClient)ENVMAIN["TAMClient"];
            }

        }
        public List<AMSTAMMModel> AMS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("AMS"))
                {
                    ENVMAIN.Add("AMS", AMLOAD());
                }
                return (List<AMSTAMMModel>)ENVMAIN["AMS"];
            }
            set
            {
                ENVMAIN["AMS"] = value;
            }
        }
        public List<SelectListItem> ERKEYES
        {
            get
            {
                if (!ENVMAIN.ContainsKey("ERKEYES"))
                {
                    ENVMAIN.Add("ERKEYES", LDK0267());
                }
                return (List<SelectListItem>)ENVMAIN["ERKEYES"];
            }
            set
            {
                ENVMAIN["ERKEYES"] = value;
            }
        }
        public List<SDDATModel> ERKEYSDB
        {
            get
            {
                if (!ENVMAIN.ContainsKey("ERKEYSDB"))
                {
                    ENVMAIN.Add("ERKEYSDB", new List<SDDATModel>());
                }
                return (List<SDDATModel>)ENVMAIN["ERKEYSDB"];
            }
        }
        public List<SelectListItem> LDK0267()
        {

            List<SelectListItem> ams = new List<SelectListItem>();
            dwData = VHP.VSD.TBMain.NewRow();
            dwData["SDSA"] = "0267";
            dwData["SDKEY"] = " AND SDKEY LIKE '%V'";
            DataSet SResult = VHP.VSD.QuerySDDAT(dwData, 267);
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                SelectListItem m = new SelectListItem();
                m.Value = row["KEY"].ToString();
                m.Text = Helper.Convert8859P1ToGB2312(row["SDES"].ToString());
                ams.Add(m);
                SDDATModel mk = new SDDATModel();
                mk.ERKEY = m.Value;
                mk.ERDES = m.Text;
                ERKEYSDB.Add(mk);
            }
            return ams;
        }
        public List<HRSTAMMModel> HRS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("HRS"))
                {
                    ENVMAIN.Add("HRS", HRLOAD());
                }
                return (List<HRSTAMMModel>)ENVMAIN["HRS"];
            }
            set
            {
                ENVMAIN["HRS"] = value;
            }
        }
        public List<HRSTAMMModel> HRLOAD()
        {

            List<HRSTAMMModel> ams = new List<HRSTAMMModel>();
            DataSet SResult = VHP.ABP.LOADHR(PM);

            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                HRSTAMMModel m = new HRSTAMMModel();
                m.HRBENID = row["HRBENID"].ToString().PadRight(8);
                m.NAME = Helper.Convert8859P1ToGB2312(row["HRVNAME"].ToString().Trim() + row["HRNNAME"].ToString().Trim());
                ams.Add(m);
            }
            return ams;
        }

        public string WRUNID
        {
            get
            {
                if (!ENVMAIN.ContainsKey("WRUNID"))
                {
                    ENVMAIN.Add("WRUNID", "");
                }
                return (string)ENVMAIN["WRUNID"];
            }
            set
            {
                ENVMAIN["WRUNID"] = value;
            }
        }

        public virtual void UAValue()
        { }
        #endregion

        #region====WB=================
        WBBSTModel _MWB;
        public WBBSTModel MWB
        {
            get
            {
                if (!ENVMAIN.ContainsKey("MWB"))
                {
                    _MWB = new WBBSTModel();
                    /*
                    if (UAClient != null)
                    {
                        var subscription = new Subscription(UAClient.DefaultSubscription) { PublishingInterval = 250 };
                        // Step 5 - Configure the subsscription with all the [MonitoredItem] attributes found in the model
                        subscription.WithModel(_MWB).AddBindings();
                        // Step 6 - Add the subscription to the session.
                        UAClient.AddSubscription(subscription);
                    }*/
                    ENVMAIN.Add("MWB", _MWB);
                }
                return (WBBSTModel)ENVMAIN["MWB"];
            }
            set
            {
                ENVMAIN["MWB"] = value;
            }
        }



        #endregion
        public string CUSER
        {
            get
            {
                if (!ENVMAIN.ContainsKey("CUSER"))
                {
                    ENVMAIN.Add("CUSER", "");
                }
                return (string)ENVMAIN["CUSER"];
            }
            set
            {
                ENVMAIN["CUSER"] = value;
            }
        }
        public bool IsLogOn
        {
            get
            {
                return (bool)ENVMAIN["IsLogOn"];
            }

        }
        public void LogOn()
        {

            ENVMAIN["IsLogOn"] = true;
        }

        public string LO
        {
            get
            {
                if (!ENVMAIN.ContainsKey("LO"))
                {
                    ENVMAIN.Add("LO", "");
                }
                return (string)ENVMAIN["LO"];
            }
            set
            {
                ENVMAIN["LO"] = value;
            }
        }
        public string LB
        {
            get
            {
                if (!ENVMAIN.ContainsKey("LB"))
                {
                    ENVMAIN.Add("LB", "");
                }
                return (string)ENVMAIN["LB"];
            }
            set
            {
                ENVMAIN["LB"] = value;
            }
        }
        public string LP
        {
            get
            {
                if (!ENVMAIN.ContainsKey("LP"))
                {
                    ENVMAIN.Add("LP", "");
                }
                return (string)ENVMAIN["LP"];
            }
            set
            {
                ENVMAIN["LP"] = value;
            }
        }
        public string SLO
        {
            get
            {
                if (!ENVMAIN.ContainsKey("SLO"))
                {
                    ENVMAIN.Add("SLO", "");
                }
                return (string)ENVMAIN["SLO"];
            }
            set
            {
                ENVMAIN["SLO"] = value;
            }
        }
        public string SLB
        {
            get
            {
                if (!ENVMAIN.ContainsKey("SLB"))
                {
                    ENVMAIN.Add("SLB", "");
                }
                return (string)ENVMAIN["SLB"];
            }
            set
            {
                ENVMAIN["SLB"] = value;
            }
        }
        public string WHP
        {
            get
            {
                if (!ENVMAIN.ContainsKey("WHP"))
                {
                    ENVMAIN.Add("WHP", "");
                }
                return (string)ENVMAIN["WHP"];
            }
            set
            {
                ENVMAIN["WHP"] = value;
            }
        }
        public List<VVTLIEFModel> VVTS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("VVTS"))
                {
                    ENVMAIN.Add("VVTS", null);
                }
                return (List<VVTLIEFModel>)ENVMAIN["VVTS"];
            }
            set
            {
                ENVMAIN["VVTS"] = value;
            }
        }


        public VVTLIEFModel MVVT
        {
            get
            {
                if (!ENVMAIN.ContainsKey("MVVT"))
                {
                    ENVMAIN.Add("MVVT", null);
                }
                return (VVTLIEFModel)ENVMAIN["MVVT"];
            }
            set
            {
                ENVMAIN["MVVT"] = value;
            }
        }
        public bool IsVVTReady
        {
            get
            {
                if (!ENVMAIN.ContainsKey("IsVVTReady"))
                {
                    ENVMAIN.Add("IsVVTReady", false);
                }
                return (bool)ENVMAIN["IsVVTReady"];
            }

            set
            {
                ENVMAIN["IsVVTReady"] = value;
            }

        }
        public bool IsVKKReady
        {
            get
            {
                if (!ENVMAIN.ContainsKey("IsVKKReady"))
                {
                    ENVMAIN.Add("IsVKKReady", false);
                }
                return (bool)ENVMAIN["IsVKKReady"];
            }

            set
            {
                ENVMAIN["IsVKKReady"] = value;
            }

        }
        public bool IsVKPReady
        {
            get
            {
                if (!ENVMAIN.ContainsKey("IsVKPReady"))
                {
                    ENVMAIN.Add("IsVKPReady", false);
                }
                return (bool)ENVMAIN["IsVKPReady"];
            }

            set
            {
                ENVMAIN["IsVKPReady"] = value;
            }

        }

        public string KRS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("KRS"))
                {
                    ENVMAIN.Add("KRS", "");
                }
                return (string)ENVMAIN["KRS"];
            }
            set
            {
                ENVMAIN["KRS"] = value;
            }
        }
        public string LFD
        {
            get
            {
                if (!ENVMAIN.ContainsKey("LFD"))
                {
                    ENVMAIN.Add("LFD", "");
                }
                return (string)ENVMAIN["LFD"];
            }
            set
            {
                ENVMAIN["LFD"] = value;
            }
        }
        public string POS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("POS"))
                {
                    ENVMAIN.Add("POS", "");
                }
                return (string)ENVMAIN["POS"];
            }
            set
            {
                ENVMAIN["POS"] = value;
            }
        }
        public int VPOS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("VPOS"))
                {
                    ENVMAIN.Add("VPOS", 0);
                }
                return (int)ENVMAIN["VPOS"];
            }
            set
            {
                ENVMAIN["VPOS"] = value;
            }
        }


        public string AUFTYP
        {
            get
            {
                if (!ENVMAIN.ContainsKey("AUFTYP"))
                {
                    ENVMAIN.Add("AUFTYP", "");
                }
                return (string)ENVMAIN["AUFTYP"];
            }
            set
            {
                ENVMAIN["AUFTYP"] = value;
            }
        }
        public string VKPAUF
        {
            get
            {
                if (!ENVMAIN.ContainsKey("VKPAUF"))
                {
                    ENVMAIN.Add("VKPAUF", "");
                }
                return (string)ENVMAIN["VKPAUF"];
            }
            set
            {
                ENVMAIN["VKPAUF"] = value;
            }
        }

        public string LIEFSCH
        {
            get
            {
                if (!ENVMAIN.ContainsKey("LIEFSCH"))
                {
                    ENVMAIN.Add("LIEFSCH", "");
                }
                return (string)ENVMAIN["LIEFSCH"];
            }
            set
            {
                ENVMAIN["LIEFSCH"] = value;
            }
        }
        public string KDKUNDNA
        {
            get
            {
                if (!ENVMAIN.ContainsKey("KDKUNDNA"))
                {
                    ENVMAIN.Add("KDKUNDNA", "");
                }
                return (string)ENVMAIN["KDKUNDNA"];
            }
            set
            {
                ENVMAIN["KDKUNDNA"] = value;
            }
        }
        public DataRow dwVKP
        {
            get
            {
                if (!ENVMAIN.ContainsKey("dwVKP"))
                {
                    ENVMAIN.Add("dwVKP", null);
                }
                return (DataRow)ENVMAIN["dwVKP"];
            }
            set
            {
                ENVMAIN["dwVKP"] = value;
            }
        }

        public VVKPOS VVKP
        {
            get
            {

                return VHP.VVKP;
            }
        }
        public VHELP VHP
        {
            get
            {
                if (!ENVMAIN.ContainsKey("VHP"))
                {
                    ENVMAIN.Add("VHP", new VHELP());
                }
                return (VHELP)ENVMAIN["VHP"];
            }
        }

        public int MORDER
        {
            get
            {
                if (!ENVMAIN.ContainsKey("MORDER"))
                {
                    ENVMAIN.Add("MORDER", 1);
                }
                return (int)ENVMAIN["MORDER"];
            }
            set
            {
                ENVMAIN["MORDER"] = value;

            }
        }



        private VICC_HRSTAMM _HR;
        public VICC_HRSTAMM HR
        {
            get
            {
                if (_HR == null) _HR = new VICC_HRSTAMM();
                return _HR;
            }
        }

        public List<WBBSTModel> WBBS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("WBBS"))
                {
                    ENVMAIN.Add("WBBS", null);
                }
                return (List<WBBSTModel>)ENVMAIN["WBBS"];
            }
            set
            {
                ENVMAIN["WBBS"] = value;
            }

        }
        public List<VKPOSModel> VKPS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("VKPS"))
                {
                    ENVMAIN.Add("VKPS", null);
                }
                return (List<VKPOSModel>)ENVMAIN["VKPS"];
            }
            set
            {
                ENVMAIN["VKPS"] = value;
            }

        }
        public string CPWBS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("CPWBS"))
                {
                    ENVMAIN.Add("CPWBS", "");
                }
                return (string)ENVMAIN["CPWBS"];
            }
            set
            {
                ENVMAIN["CPWBS"] = value;
            }

        }
        public string APPID
        {
            get
            {
                if (!ENVMAIN.ContainsKey("APPID"))
                {
                    ENVMAIN.Add("APPID", "");
                }
                return (string)ENVMAIN["APPID"];
            }
            set
            {
                ENVMAIN["APPID"] = value;
            }

        }
        public string APPSECRET
        {
            get
            {
                if (!ENVMAIN.ContainsKey("APPSECRET"))
                {
                    ENVMAIN.Add("APPSECRET", "");
                }
                return (string)ENVMAIN["APPSECRET"];
            }
            set
            {
                ENVMAIN["APPSECRET"] = value;
            }

        }
        public Dictionary<string, object> USERS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("USERS"))
                {
                    ENVMAIN.Add("USERS", new Dictionary<string, object>());
                }
                return (Dictionary<string, object>)ENVMAIN["USERS"];
            }
            set
            {
                ENVMAIN["USERS"] = value;
            }

        }
        public Dictionary<string, object> CARDS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("CARDS"))
                {
                    ENVMAIN.Add("CARDS", new Dictionary<string, object>());
                }
                return (Dictionary<string, object>)ENVMAIN["CARDS"];
            }
            set
            {
                ENVMAIN["CARDS"] = value;
            }

        }
        public string ACCESSTOKEN
        {
            get
            {
                if (!ENVMAIN.ContainsKey("ACCESSTOKEN"))
                {
                    ENVMAIN.Add("ACCESSTOKEN", "");
                }
                return (string)ENVMAIN["ACCESSTOKEN"];
            }
            set
            {
                ENVMAIN["ACCESSTOKEN"] = value;
            }

        }
        public string OPENID
        {
            get
            {
                if (!ENVMAIN.ContainsKey("OPENID"))
                {
                    ENVMAIN.Add("OPENID", "");
                }
                return (string)ENVMAIN["OPENID"];
            }
            set
            {
                ENVMAIN["OPENID"] = value;
            }

        }

        public DataTable WBLIST
        {
            get
            {
                if (!ENVMAIN.ContainsKey("WBLIST"))
                {
                    ENVMAIN.Add("WBLIST", null);
                }
                return (DataTable)ENVMAIN["WBLIST"];
            }
            set
            {
                ENVMAIN["WBLIST"] = value;
            }

        }
        public int TWBS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("TWBS"))
                {
                    ENVMAIN.Add("TWBS", 0);
                }
                return (int)ENVMAIN["TWBS"];
            }
            set
            {
                ENVMAIN["TWBS"] = value;
            }

        }
        public int HWBS
        {
            get
            {
                if (!ENVMAIN.ContainsKey("HWBS"))
                {
                    ENVMAIN.Add("HWBS", 0);
                }
                return (int)ENVMAIN["HWBS"];
            }
            set
            {
                ENVMAIN["HWBS"] = value;
            }
        }
        public List<WBBSTModel> WBBSF
        {
            get
            {
                if (!ENVMAIN.ContainsKey("WBBSF"))
                {
                    ENVMAIN.Add("WBBSF", null);
                }
                return (List<WBBSTModel>)ENVMAIN["WBBSF"];
            }
            set
            {
                ENVMAIN["WBBSF"] = value;
            }

        }
        public Dictionary<string, object> EnvExe
        {
            get
            {
                return app.EnvExe;
            }
        }
        public ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }

        public string AgentID
        {
            get
            {
                return app.AgentID;
            }
        }

        public string RUNID = "";
        public string MESSAGES = "";
        public ITXController()
        {
            string info = "";
            app.IsSTA = false;
            app.UserIP = ClientIP;
            app.ENVMAIN(ClientIP);
            ModelState.AddModelError("", ClientIP);
            if (!IsLogOn)
            {
                //ModelState.AddModelError("", "NotLogOn");
                app.Load();
                //ModelState.AddModelError("", info);
            }
            PM = new Dictionary<string, object>();
            ViewBag.IP = GetIp();
            ViewBag.IsLogOn = IsLogOn;
            if (ViewBag.IsLogOn)
            {
                ViewBag.UserID = CUSER;
            }
            else
            {
                ViewBag.UserID = "请登陆";
            }
        }
        Dictionary<string, object> UserList
        {
            get
            {
                return app.UserList;
            }
        }
        public string GetIp()
        {
            string user_IP;
            HttpRequest request = System.Web.HttpContext.Current.Request;
            if (request.ServerVariables["HTTP_VIA"] != null)
            {
                user_IP = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else
            {
                user_IP = request.ServerVariables["REMOTE_ADDR"].ToString();
            }
            //user_IP = GetMacAddress();
            return user_IP;
        }
        string GetMacAddress()
        {
            try
            {
                string mac = "";
                ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    if ((bool)mo["IPEnabled"] == true)
                    {
                        mac = mo["MacAddress"].ToString();
                        break;
                    }
                }
                moc = null;
                mc = null;
                return mac;
            }
            catch
            {
                return "unknow";
            }
        }


        //
        // GET: /Account/Login 

        #region Helpers
        public ActionResult RedirectToLocal(string returnUrl)
        {
            if (Url.IsLocalUrl(returnUrl))
            {
                return Redirect(returnUrl);
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
        }

        public enum ManageMessageId
        {
            ChangePasswordSuccess,
            SetPasswordSuccess,
            RemoveLoginSuccess,
        }

        public List<AMSTAMMModel> AMLOAD()
        {

            List<AMSTAMMModel> ams = new List<AMSTAMMModel>();
            DataSet SResult = VHP.ABP.LOADAM(PM);

            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                AMSTAMMModel m = new AMSTAMMModel();
                m.MACHINEID = row["AMBDEMA"].ToString().Trim();
                m.DES = Helper.Convert8859P1ToGB2312(row["AMBEZ"].ToString());
                m.MKRS = row["AMNRKRS"].ToString();
                m.MLFD = row["AMLFDNR"].ToString();
                m.MPOS = row["AMPOS"].ToString();
                m.KKRS = row["AMKSTKRS"].ToString();
                m.KKST = row["AMKST"].ToString();
                m.MLO = row["AMLO"].ToString();
                m.MLB = row["AMLB"].ToString();
                m.MLP = row["AMLPLATZ"].ToString();
                m.UIAM.KEY = m.KKRS + m.MLFD + m.MPOS;
                ams.Add(m);
            }
            return ams;
        }
        internal class ExternalLoginResult : ActionResult
        {
            public ExternalLoginResult(string provider, string returnUrl)
            {
                Provider = provider;
                ReturnUrl = returnUrl;
            }

            public string Provider { get; private set; }
            public string ReturnUrl { get; private set; }

            public override void ExecuteResult(ControllerContext context)
            {
                //OAuthWebSecurity.RequestAuthentication(Provider, ReturnUrl);
            }
        }

        private static string ErrorCodeToString(MembershipCreateStatus createStatus)
        {
            // See http://go.microsoft.com/fwlink/?LinkID=177550 for
            // a full list of status codes.
            switch (createStatus)
            {
                case MembershipCreateStatus.DuplicateUserName:
                    return "User name already exists. Please enter a different user name.";

                case MembershipCreateStatus.DuplicateEmail:
                    return "A user name for that e-mail address already exists. Please enter a different e-mail address.";

                case MembershipCreateStatus.InvalidPassword:
                    return "The password provided is invalid. Please enter a valid password value.";

                case MembershipCreateStatus.InvalidEmail:
                    return "The e-mail address provided is invalid. Please check the value and try again.";

                case MembershipCreateStatus.InvalidAnswer:
                    return "The password retrieval answer provided is invalid. Please check the value and try again.";

                case MembershipCreateStatus.InvalidQuestion:
                    return "The password retrieval question provided is invalid. Please check the value and try again.";

                case MembershipCreateStatus.InvalidUserName:
                    return "The user name provided is invalid. Please check the value and try again.";

                case MembershipCreateStatus.ProviderError:
                    return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";

                case MembershipCreateStatus.UserRejected:
                    return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";

                default:
                    return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
            }
        }

        protected override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            /*
            var weixinFileVersionInfo = FileVersionInfo.GetVersionInfo(Server.MapPath("~/bin/Senparc.Weixin.dll"));
            var mpFileVersionInfo = FileVersionInfo.GetVersionInfo(Server.MapPath("~/bin/Senparc.Weixin.MP.dll"));
            var extensionFileVersionInfo = FileVersionInfo.GetVersionInfo(Server.MapPath("~/bin/Senparc.Weixin.MP.MvcExtension.dll"));

            TempData["WeixinVersion"] = string.Format("{0}.{1}", weixinFileVersionInfo.FileMajorPart, weixinFileVersionInfo.FileMinorPart); //Regex.Match(weixinFileVersionInfo.FileVersion, @"\d+\.\d+");
            TempData["MpVersion"] = string.Format("{0}.{1}", mpFileVersionInfo.FileMajorPart, mpFileVersionInfo.FileMinorPart); //Regex.Match(mpFileVersionInfo.FileVersion, @"\d+\.\d+");
            TempData["ExtensionVersion"] = string.Format("{0}.{1}", extensionFileVersionInfo.FileMajorPart, extensionFileVersionInfo.FileMinorPart); //Regex.Match(extensionFileVersionInfo.FileVersion, @"\d+\.\d+");
            */
            base.OnResultExecuting(filterContext);
        }
        #endregion
    }
}
